/**
 * 房源信息公共window
 */
Ext.define('component.batch.sellCancelControlWindow', {
	extend : 'Ext.window.Window',
	callbackFun : function(record) {
		Ext.Msg.alert('提示', '回调函数未配置！');
	},
	config : {
		roomIds : '',
		userName: '',
		treeId:''
	},
	initComponent : function() {
		var me = this;
		var roomIds = this.roomIds;
		var userName = this.userName;
		var treeId = this.treeId;
		var sellCancelControlGridStore = Ext.create('Ext.data.Store', {
        	fields: ["id", "combinedName"
                 , "houseTypeName","buildingArea","sharingArea"
                 ,"innerArea","billingArea","buildingPrice","totalAmount","day",
                 "danjia","zongjia","valuationType"],
        	pageSize: 10,  //页容量50条数据
        	//是否在服务端排序 （true的话，在客户端就不能排序）
        	remoteSort: false,
        	proxy: {
	            type: 'ajax',
	            url: jypath+'/estate/projectRoom/list',
	            actionMethods: { read: 'POST' },
	            reader: {
	                type: 'json',
	                root: 'rows',
	                totalProperty: 'total'
	            },
	            extraParams: {
	                ids: roomIds,
	                roomStatus: '6'
	            }
        	},
        	autoLoad: true  //即时加载数据
    	});
	
		var sellCancelControlGrid = Ext.create("Ext.grid.Panel", {
			title: '批量撤控房源',
			height:550,
	        store: sellCancelControlGridStore,
	        columnLines: true,
	        collapsible: true,
	        columns: [
				{
		            text: '房号',
		            dataIndex: 'combinedName',
		            width:350
        		},{
		            text: '房态', width:50,
		            renderer: function() {
		                return '可售';
		            }
	        	},{
		            text: '户型', width:100,
		            dataIndex: 'houseTypeName',
		            renderer : function(val) {
		                if (val == 0) {
		                    return '正常';
		                } else if (val == 1) {
		                    return '已关闭';
		                }
		                return val;
		            }
	        	},{
		            text: '建筑面积(平方米)', width:100,
		            dataIndex: 'buildingArea'
	        	},{
		            text: '分摊面积(平方米)', width:100,
		            dataIndex: 'sharingArea'
	        	},{
		            text: '套内面积(平方米)', width:100,
		            dataIndex: 'innerArea'
	        	},{
		            text: '计价面积(平方米)', width:100,
		            dataIndex: 'valuationType',
		            renderer : function(value,cellmeta,record,rowIndex,columnIndex,store) {
		                var rec = sellCancelControlGrid.getStore().getAt(rowIndex);
		            	if(rec.get('valuationType')==1){
		            		var open = rec.get('buildingArea');
		                    return open;
		                } else if (rec.get('valuationType')==2) {
		                	var open = rec.get('innerArea');
		                    return open;
		                }
		                return value;
		            }
	        	},{
		            text: '单价(元)', dataIndex: 'danjia', width:100,
		            renderer: Ext.util.Format.numberRenderer('0,000.00')
	        	},{
		            text: "总价(元)", dataIndex: 'zongjia', width:100,
		            renderer: Ext.util.Format.numberRenderer('0,000.00')
	        	}/*,{
		            text: "库存时间（天）", dataIndex: 'day', width:100
	        	}*/
	        ]
		});
		
		var sellCancelControlInfo = Ext.create('Ext.form.FormPanel',{
			title:'撤控信息',
			frame: true,
	       	collapsible: false,
	       	autoScroll:false,
		   	items:[
			{
				xtype : "container",
				layout : "hbox",
				items : [{
					xtype : 'textarea',
					fieldLabel : '撤控原因',
					width:500,
					id:'reason',
					allowBlank:false,
			    	blankText:'不能为空'
				}]
			},
			{
				xtype : "container",
				layout : "hbox",
				items : [{
					xtype : 'displayfield',
					fieldLabel : '经办人',
					value:userName
				}]
			}],
			dockedItems: [{
	            xtype: 'toolbar',
	            dock: 'bottom',
	            ui: 'footer',
	            layout: {
	                pack: 'center'
	            },
	            items: [{
	            	xtype: "button",
	                minWidth: 80,
	                text: '保存',
	                id:'save_button',
	                handler:function(){
	           			var form = sellCancelControlInfo.getForm();
	                  	if(form.isValid()){
	                  		Ext.getCmp("save_button").hide();
	                		var parent={
	                			'ids': roomIds,
	                			'remark': Ext.getCmp("reason").getValue(),
	                			'controlType': 1 //0销控 1撤销销控
		                	};
	                  	  	Ext.Ajax.request({
		                		url:jypath+'/marketing/sellControl/batchSellControlRevoke',
		                		params: parent,
		                		callback: function (options, success, response) {
		                			var obj = JSON.parse(response.responseText);
		                			if(obj.res=="1"){
		                				if(treeId!=null&&treeId!=""){
		                					Ext.MessageBox.alert("系统提示","保存成功", function(){
		                						me.close();
			    								Ext.getCmp("centerBody").removeAll();
			                					var roomSwitchList=Ext.create('component.room.switch',{
			                						treeId: treeId
			                					});
			                					Ext.getCmp("centerBody").add(roomSwitchList);
			                					$("#tab_type").val(2);
			    							});
		                				}else{
		                					Ext.MessageBox.alert("系统提示","保存成功", function(){
			    								history.go(0);
			    							});
		                				}
		    							
		    						}else{
		    							Ext.MessageBox.alert("系统提示",obj.resMsg); 
		    						}
		                		}
		        			});
	                  	}
	                }
	            },{
	            	xtype: "button",
	                minWidth: 80,
	                text: '关闭',
	                handler:function(){
	                	me.close();
          			}
	        	}]
			}]
		});

		var mainPanel=Ext.create('Ext.panel.Panel', {
			autoScroll: true,
		    items:[sellCancelControlGrid, sellCancelControlInfo]
		});
		
		var defaultConfig = {
			frame:true,
			title : '房源撤控',
			width: 700,
			height: 550,
		    plain: true,
	        modal: true,
			layout : 'fit',
			items:[mainPanel]
		};
		
		Ext.apply(this,defaultConfig);
		this.callParent();
	}
});